<template>
	<view>

		<template v-if='loading'>
			<view v-for="(item,index) in 5" :key="index">
				<view class=" Skeleton" style="height: 30rpx;" />
				<view class="activeContent" style="border: none;">
					<view>
						<album :loading='loading' />
					</view>
					<view class=" Skeleton" style="height: 30rpx;margin-top: 20rpx;" />
				</view>
			</view>
		</template>
		<template v-else>
			<view class="activeBox" v-for="(item,index) in active" :key="index">
				<view class="created_at">
					<u-avatar :src='item.customer.avatar' size='80rpx' />
					<view style="margin:0 10rpx;flex: 1;">
						<u-text lines='1' :text='item.decorates.remark_name' size='24rpx' />
						<u-text lines='1' :text='item.customer.nick_name'  size='24rpx' color='#999' />
					</view>
					<text>{{item.created_at | changeTime}}</text>
				</view>
				<view class="activeContent">
					<view class="content">
						<view class="iconBox" v-if="item.status!=-1" @click.stop="()=>{}">
							<view>
								<u-notice-bar v-if="item.status==1" :text="'审核失败：'+item.remark" mode="closable"
									:bgColor='"rgba(255,0,0,0.5)"' color='#fff'></u-notice-bar>
								<u-alert v-if="item.status==2" title="审核通过" type="success"></u-alert>
							</view>
						</view>
						<view style="margin: 10rpx 0;">
							<u-parse :content="item.title"></u-parse>
						</view>
						<view class="albumBox" v-if="item.images.length||item.videos.length">
							<view class="process">
								{{item.process.title}}
							</view>
							<album :ref='`album${index}`' :imageList='item.images'
								:video='item.videos.map(imageItem=>imageItem.url)' :index='index'
								:playIndex='playIndex' />
						</view>
						<view class="userBox">
							<u-avatar :src='item.user.avatar' size='60rpx' />
							<view>
								<u-text :lines='1' :text='item.user.nick_name' size='24rpx' />
								<u-text :lines='1' :text='item.decorates.district' prefixIcon='map' size='24rpx'
									color='#999' />
							</view>
							<u-icon name="more-dot-fill" size="40rpx" @click='openSelect(item)'></u-icon>
						</view>
					</view>
				</view>
			</view>
		</template>
		<root-portal>
			<u-action-sheet :actions="columns" :show="selectShow" @close='selectShow=false' @select="confirm"
				closeOnClickOverlay></u-action-sheet>
			<u-modal :show="delShow" content='是否确认删除？' showCancelButton @confirm='del'
				@cancel='delShow=false'></u-modal>

			<activeVerify @reload='reload' :show='verifyId' @close='verifyId=0'></activeVerify>
		</root-portal>
	</view>
</template>

<script>
	import album from '@/components_company/album.vue';
	import activeVerify from '@/components_company/activeVerify.vue';
	export default {
		components: {
			album,
			activeVerify
		},
		props: ['loading', 'active', 'playIndex'],
		data() {
			return {
				delShow: false,
				selectShow: false,
				selectItem: null,
				columns: [{
						name: '编辑'
					},
					{
						name: '删除'
					},
					{
						name: '审核'
					},
				],
				verifyId: null
			}
		},
		methods: {
			del() {
				this.delShow = false
				this.$emit('loadingChange')
				this.$api_company.Active.Del(this.selectItem.id).then(res => {
					this.$emit('reload')
				}).catch(err => {
					this.$emit('loadingChange')
				})
			},
			reload() {
				this.$emit('reload')
			},
			openSelect(item) {
				this.selectShow = true
				this.selectItem = item
				this.$emit('refresher_enabled_change', false)
			},
			upDate() {
				this.$utils.navigateTo({
					url: "/active/upDate?id=" + this.selectItem.id
				})
			},
			confirm(e) {
				this.selectShow = false
				this.$emit('refresher_enabled_change', true)
				if (e.name == '编辑') {
					if (this.selectItem.status == 2) {
						uni.$u.toast('审核已通过，不能编辑')
						return
					}
					this.upDate()
				} else if (e.name == '删除') {
					this.delShow = true
				} else if (e.name == '审核') {
					if (this.selectItem.status == 2) {
						uni.$u.toast('审核已通过，无需在审核')
						return
					}
					this.Verify()
				}
			},
			Verify() {
				this.verifyId = this.selectItem.id
				this.$emit('refresher_enabled_change', false)
			},
		}
	}
</script>

<style lang="scss" scoped>
	.created_at {
		font-size: 24rpx;
		display: flex;
		align-items: center;
		margin-right: 40rpx;
		align-items: center;
	}

	.activeContent {
		padding: 0 0 0 45rpx;
		margin: 10rpx 0 10rpx 35rpx;
		border-left: 1rpx dashed #bbb;

		>.content {
			box-shadow: 0 0 10rpx #ddd;
			margin-right: 30rpx;
			padding: 20rpx;
			border-radius: 8rpx;
			background-color: #fff;
		}
	}

	.operationBox {
		display: flex;
		justify-content: flex-end;
	}

	.userBox {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: 20rpx 0;

		view:nth-child(2) {
			flex: 0.98;
		}
	}

	.iconBox {
		display: flex;
		justify-content: space-between;
		width: 100%;
		margin-bottom: 20rpx;

		>view:nth-child(1) {
			flex: 1;
			margin-right: 10rpx;
		}
	}

	.albumBox {
		position: relative;
	}

	.process {
		position: absolute;
		z-index: 11;
		padding: 10rpx 20rpx;
		background: rgba(0, 0, 0, 0.3);
		top: 20rpx;
		left: 20rpx;
		color: #fff;
		border-radius: 8rpx;
	}
</style>